//TODO 优化编码
import { SET_CAROUSEL, SET_LOGIN_VISIBLE, SET_BLOG_PAGEDATA, SET_BLOG_TAGS,SET_BLOG_ITEM_HOVER_STATUS } from '@/store/mutation-types'
import { blogPageQuery, blogTagQuery } from '@/api/blog'
import router from '../../router'

const BlogIndex = {

  state: {
    blogItemHoverStatus:false,//博客鼠标进入状态
    blogTags: [],//博客标签
    blogPageData: [],//博客列表分页数据
    loginVisible: false, //是否显示登录弹框,
    carouselShowStatus: true //首页carousel显示状态
  },

  actions: {
    /**
     * 设置博客鼠标进入状态
     * @param commit
     * @param isShow
     */
    setBlogItemHoverStatus({ commit }, blogItemHoverStatus) {
      commit(SET_BLOG_ITEM_HOVER_STATUS, blogItemHoverStatus)
    },
    /**
     * 设置博客列表分页数据
     * @param commit
     * @param listData 列表分页数据
     */
    setBlogTags({ commit }) {
      blogTagQuery().then(function(res) {
        commit(SET_BLOG_TAGS, res.data)
      })
    },
    /**
     * 设置博客列表分页数据
     * @param commit
     * @param listData 列表分页数据
     */
    setBlogPageData({ commit }, { current, size, categoryId, tagId }) {
      blogPageQuery(current, size, categoryId, tagId).then(function(res) {
        commit(SET_BLOG_PAGEDATA, res.data)
        router.push('/blog/index')
      })
    },
    /**
     * 设置登陆页面是否可见
     * @param commit
     * @param direction 滚动方向:up,down
     */
    setLoginVisible({ commit }, isShow) {
      commit(SET_LOGIN_VISIBLE, isShow)
    },
    /**
     * 设置当前是否显示走马灯
     * @param commit
     * @param direction 滚动方向:up,down
     */
    setCarousel({ commit }, isShow) {
      commit(SET_CAROUSEL, isShow)
    }

  },

  mutations: {
    [SET_BLOG_ITEM_HOVER_STATUS]: (state,blogItemHoverStatus ) => {
      state.blogItemHoverStatus = blogItemHoverStatus
    },
    [SET_CAROUSEL]: (state, isShow) => {
      state.carouselShowStatus = isShow
    },
    [SET_LOGIN_VISIBLE]: (state, isShow) => {
      state.loginVisible = isShow
    },
    [SET_BLOG_PAGEDATA]: (state, blogPageData) => {
      state.blogPageData = blogPageData
    },
    [SET_BLOG_TAGS]: (state, blogTags) => {
      state.blogTags = blogTags
    }
  }

}

export default BlogIndex
